// pages/enlistManage2/enlistManage2.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    list:[],
    check:0,
    noAdopt:0,
    noCheck:0,
    pageNumber:1,
    pageSize:10,
    totalPages:'',
    name:'',
    name1:'',
    ischeck:false,
    isrefuse:false,
    ismodal:false,
    participantId:'',
  },
  loadList: function () {
    var that = this;
    app.req({
      url: "wechat/act/participation/participantListDetail",
      method: "post",
      data: {
        activityId: that.data.id,
        type:1,
        pageNumber: that.data.pageNumber,
        pageSize: that.data.pageSize,
      },
      success: function (res) {
        if (200 == res.code) {
          that.setData({
            list: that.data.list.concat(res.data.list.rows),
            noCheck: res.data.noCheck,
            check: res.data.check,
            noAdopt: res.data.noAdopt,
            totalPages: res.data.list.totalPages
          })
          console.log("人员列表", res)

        }
      }
    })
  },
  checkbtn(e){
    var that = this
    console.log(e)
    var name = e.currentTarget.dataset.name
    var participantId = e.currentTarget.dataset.id
    that.setData({
      participantId: participantId,
      name:name,
      ischeck:true,
      ismodal: true,
    })
  },
//拒绝参见
  cancelbtn(e){
    var that = this
    console.log(e)
    var name = e.currentTarget.dataset.name
    var participantId = e.currentTarget.dataset.id
    that.setData({
      participantId: participantId,
      name1: name,
      isrefuse: true,
      ismodal:true,
    })
  },
  refusecheck(){
    var that = this
    if(that.data.ischeck){
      app.req({
        url: "wechat/activity/review",
        method: "post",
        data: {
          activityId: that.data.id,
          msgId: "",
          participantId: that.data.participantId,
          type: 2,
        },
        success: function (res) {
          if (200 == res.code) {
            that.onShow()
            wx.showToast({
              title: "操作成功",
              icon: 'none',
              duration: 2000
            })
            that.setData({
              ischeck:false,
              participantId:'',
              ismodal:false,
              name:'',
            })
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none',
              duration: 2000
            })
            that.setData({
              ischeck: false,
              participantId: '',
              ismodal: false,
              name: '',
            })
          }
        }
      })
    }else if(that.data.isrefuse){
      app.req({
        url: "wechat/act/participation/exit",
        method: "post",
        data: {
          activityId: that.data.id,
          participantId: that.data.participantId,
          type: 2,
        },
        success: function (res) {
          if (200 == res.code) {
            that.onShow()
            wx.showToast({
              title: "操作成功",
              icon: 'none',
              duration: 2000
            })
            that.setData({
              isrefuse: false,
              participantId: '',
              ismodal: false,
              name1: '',
            })
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none',
              duration: 2000
            })
            that.setData({
              isrefuse: false,
              participantId: '',
              ismodal: false,
              name1: '',
            })
          }
        }
      })
    }
  },
  adoptcheck(){
    var that = this
    if(that.data.ischeck){
      app.req({
        url: "wechat/activity/review",
        method: "post",
        data: {
          activityId: that.data.id,
          msgId: "",
          type: 1,
          participantId: that.data.participantId
        },
        success: function (res) {
          if (200 == res.code) {
            wx.showToast({
              title: "审核成功",
              icon: 'none',
              duration: 2000
            })
            that.setData({
              ischeck: false,
              participantId: '',
              ismodal: false,
              name: '',
            })
            that.onShow()
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none',
              duration: 2000
            })
            that.setData({
              ischeck: false,
              participantId: '',
              ismodal: false,
              name: '',
            })
          }
        }
      })
    }else if(that.data.isrefuse){
      app.req({
        url: "wechat/act/participation/exit",
        method: "post",
        data: {
          activityId: that.data.id,
          type: 1,
          participantId: that.data.participantId
        },
        success: function (res) {
          if (200 == res.code) {
            that.onShow()
            wx.showToast({
              title: "审核成功",
              icon: 'none',
              duration: 2000
            })
            that.setData({
              isrefuse: false,
              participantId: '',
              ismodal: false,
              name1: '',
            })
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none',
              duration: 2000
            })
            that.setData({
              isrefuse: false,
              participantId: '',
              ismodal: false,
              name1: '',
            })
          }
        }
      })
    }
  },
  hide(){
    var that = this
    that.setData({
      isrefuse: false,
      ischeck:false,
      participantId: '',
      ismodal: false,
      name1: '',
      name:'',
    })
  },
  preventTouchMove(){},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      id: options.id
    })
    console.log('活动id',that.data.id)
    app.getUserInfo(function (userInfo) {
      // that.toggle("userInfo", userInfo);
    })
    wx.setNavigationBarTitle({
      title:'活动审核'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      pageNumber:1,
      pageSize:10,
      list:[],
    })
    this.loadList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if (that.data.totalPages > that.data.pageNumber){
      that.setData({
        pageNumber: that.data.pageNumber+1,
        pageSize:10
      })
      this.loadList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})